<fieldset>
    <legend>条件搜索</legend>
    <form action="{:request()->url()}" autocomplete="off" class="layui-form layui-form-pane form-search" method="get" onsubmit="return false">
        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">用户手机</label>
            <label class="layui-input-inline">
                <input class="layui-input" name="user_phone" placeholder="请输入用户手机" value="{$get.user_phone|default=''}">
            </label>
        </div>

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">用户昵称</label>
            <label class="layui-input-inline">
                <input class="layui-input" name="user_nickname" placeholder="请输入用户昵称" value="{$get.user_nickname|default=''}">
            </label>
        </div>

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">订单单号</label>
            <label class="layui-input-inline">
                <input class="layui-input" name="order_no" placeholder="请输入订单单号" value="{$get.order_no|default=''}">
            </label>
        </div>

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">发货单号</label>
            <label class="layui-input-inline">
                <input class="layui-input" name="truck_number" placeholder="请输入发货单号" value="{$get.truck_number|default=''}">
            </label>
        </div>

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">发货状态</label>
            <label class="layui-input-inline">
                <select class="layui-select" name="status">
                    <option value="">-- 全部 --</option>
                    {foreach ['已经取消','等待发货','已经发货'] as $k=>$v}
                    {if input('status') eq $k.''}
                    <option selected value="{$k}">{$v}</option>
                    {else}
                    <option value="{$k}">{$v}</option>
                    {/if}{/foreach}
                </select>
            </label>
        </div>

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">提交时间</label>
            <label class="layui-input-inline">
                <input class="layui-input" data-date-range name="address_datetime" placeholder="请选择提交时间" value="{$get.address_datetime|default=''}">
            </label>
        </div>

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">发货时间</label>
            <label class="layui-input-inline">
                <input class="layui-input" data-date-range name="send_datetime" placeholder="请选择发货时间" value="{$get.send_datetime|default=''}">
            </label>
        </div>

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">收货姓名</label>
            <label class="layui-input-inline">
                <input class="layui-input" name="address_name" placeholder="请输入收货姓名" value="{$get.address_name|default=''}">
            </label>
        </div>

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">收货手机</label>
            <label class="layui-input-inline">
                <input class="layui-input" name="address_phone" placeholder="请输入收货手机" value="{$get.address_phone|default=''}">
            </label>
        </div>

        <div class="layui-form-item layui-inline">
            <label class="layui-form-label">配送地址</label>
            <label class="layui-input-inline">
                <input class="layui-input" name="address_content" placeholder="请输入配送地址" value="{$get.address_content|default=''}">
            </label>
        </div>

        <div class="layui-form-item layui-inline">
            <button class="layui-btn layui-btn-primary" type="submit"><i class="layui-icon">&#xe615;</i> 搜 索</button>
            <button class="layui-btn layui-btn-primary" data-form-export="{:url('index')}?type={$type|default=''}" type="button">
                <i class="layui-icon layui-icon-export"></i> 导 出
            </button>
        </div>
    </form>
</fieldset>

<script>
    window.form.render();
    require(['excel'], function (excel) {
        excel.bind(function (data) {
            var rows = [];
            data.forEach(function (order) {
                order.items.forEach(function (item) {
                    rows.push([
                        order.order_no,
                        item.goods_name,
                        item.goods_sku,
                        item.goods_spec,
                        item.stock_sales,
                        item.price_selling,
                        item.total_selling,
                        '{$address.name|default=""}',
                        order.truck.address_idcode,
                        order.truck.address_name,
                        order.truck.address_phone,
                        order.truck.address_province,
                        order.truck.address_city,
                        order.truck.address_area,
                        order.truck.address_content,
                    ]);
                });
            });
            rows.unshift([
                '订单号', '物品名称', '物品SKU编码', '物品规格描述', '数量', '单价', '总额',
                '寄件方', '身份证号', '收货人', '电话', '省份', '城市', '区', '地址'
            ]);
            return rows;
        }, '订单发货记录');
    });
</script>